<?php

!defined('IN_TIPASK') && exit('Access Denied');

class expertmodel {

    var $db;
    var $base;

    function expertmodel(&$base) {
        $this->base = $base;
        $this->db = $base->db;
    }
    function get_list($start=0,$limit=3) {
        $expertlist = array();
        $query = $this->db->query("SELECT e.uid,e.username,e.categoryname,u.credit1,u.lastlogin,u.answers  FROM ".DB_TABLEPRE."expert as e,".DB_TABLEPRE."user as u WHERE u.uid=e.uid ORDER BY u.credit1 DESC LIMIT $start ,$limit");
        while($expert = $this->db->fetch_array($query)) {
            $expert['avatar']=get_avatar_dir($expert['uid']);
            $expert['lastlogin']=tdate($expert['lastlogin']);
            $expertlist[] = $expert;
        }
        return $expertlist;
    }
    function get_by_uid($uid){
    	return $this->db->fetch_array($this->db->query("SELECT * FROM ".DB_TABLEPRE."expert WHERE `uid`=$uid"));
    }
    function get_by_username($username){
        return $this->db->fetch_array($this->db->query("SELECT * FROM ".DB_TABLEPRE."expert WHERE `username`='$username'"));
    }
    function add($uid,$username,$categoryname){
        $this->db->query("INSERT INTO ".DB_TABLEPRE."expert(`uid`,`username`,`categoryname`) VALUES($uid,'$username','$categoryname')");
    }

    function remove($uids){
        $this->db->query("DELETE FROM ".DB_TABLEPRE."expert WHERE uid IN ($uids)");
    }
}

?>
